﻿<%@ Page Language="C#" Inherits="EasyFMS.Common.ViewPageBase" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>EasyFMS主页</title>
    <link rel="stylesheet" type="text/css" href="Content/Css/OperaMasksUI/default/om-all.css" />
    <link rel="stylesheet" type="text/css" href="Content/Css/home.css" />
    <script type="text/javascript" src="Scripts/jquery.1.6.3.min.js"></script>
    <script type="text/javascript" src="Scripts/json2.js"></script>
    <script type="text/javascript" src="Scripts/OperaMasksUI/operamasks-ui.min.js"></script>
    <script type="text/javascript" src="Scripts/Plugin/artDialog4.1.7/jquery.artDialog.js?skin=default"></script>
    <script type="text/javascript" src="Scripts/Plugin/artDialog4.1.7/plugins/iframeTools.js"></script>
    <script type="text/javascript" src="Scripts/banBackSpace.js"></script>
    <script type="text/javascript">
        var goOn = true, loadMenu, centerTab, ifh, currentName, currentUID;

        $(document).ready(function () {
            //同步获取用户信息
            $.ajax({
                cache: false, async: false,
                url: 'handler/ajax.ashx?type=AjaxSystem&method=loginIn',
                dataType: 'json', type: 'post',
                beforeSend: function () {
                    $.omMessageBox.waiting({
                        title: '请等待',
                        content: '服务器正在加载用户信息,请稍后...'
                    });
                },
                complete: function () {
                    $.omMessageBox.waiting("close");
                },
                success: function (data) {
                    if (data.IsError) {
                        goOn = false;
                        $.omMessageBox.alert({
                            content: '发现系统错误,请重新登录<BR>错误码：' + data.Message,
                            onClose: function () {
                                window.top.location.href = decodeURIComponent("Index.aspx");
                            }
                        });
                    }
                    else {
                        goOn = true;
                        currentName = data.Data.username;
                        currentUID = data.Data.userid;
                    }
                },
                error: function (result) {
                    goOn = false;
                    $.omMessageBox.alert({
                        content: '发现系统错误,请重新登录<BR>错误码：' + result.status,
                        onClose: function () {
                            window.top.location.href = decodeURIComponent("Index.aspx");
                        }
                    });
                }
            });

            if (goOn) {
                var element = $('body').omBorderLayout({
                    fit: true,
                    spacing: 0,
                    panels: [{
                        id: "south-panel",
                        region: "south",
                        title: '<span style="color:#15428B;font-weight: bold;padding:6px;">系统操作员:<span class="top-username">' + currentName + '</span></span><span id="button-delete" style="float:right;text-align:center;cursor:pointer;">[<a href="javascript:f_loginout()">退出系统</a>]</span><span id="button-delete" style="float:right;text-align:center;cursor:pointer;">[<a href="javascript:f_changepwd()">修改密码</a>]</span><span id="button-delete" style="float:right;text-align:center;cursor:pointer;">[<a href="http://www.heyuesoftware.com" target="_blank">欢迎使用EasvFMS</a>]</span>',
                        header: true,
                        resizable: false,
                        collapsible: false
                    }, {
                        id: "center-panel",
                        header: false,
                        title: "中间模块",
                        region: "center"
                    }, {
                        id: "west-panel",
                        resizable: true,
                        collapsible: true,
                        title: '<img id="menuRefresh" src="Content/Images/refresh.png" alt="刷新菜单" style="cursor:pointer;" /><img id="tagCloseAll" src="Content/Images/cancel.png" alt="关闭所有打开窗口" style="cursor:pointer;" />',
                        region: "west", width: 190
                    }]
                });

                centerTab = $('#center-tab').omTabs({
                    closable: false,
                    border: false,
                    width: '100%',
                    height: '100%'
                });
                ifh = centerTab.height() - centerTab.find(".om-tabs-headers").outerHeight() - 20;
                $("#mydesk").height(ifh)

                $("#menuRefresh").bind("click", function () {
                    loadMenu();
                })
                $("#tagCloseAll").bind("click", function () {
                    closeAllTag();
                })
                loadMenu();
            }
        });
        //添加tabid定义
        var CreateTabIDs = '';

        closeAllTag = function () {

            var arr = CreateTabIDs.split(",");
            var c = arr.length;
            for (i = 0; i < c; i++) {
                var tabId = centerTab.omTabs('getAlter', arr[i]);
                if (tabId) {
                    //centerTab.omTabs('close', 'tab_' + $("div[class='nav-item']")[i].id);
                    centerTab.omTabs('close', arr[i]);
                }
            }
            CreateTabIDs = "";


        }
        function TreeNodeClick(node, event) {
            if (node.url) { customerAddTab(centerTab, node.id, node.url + '?menuid=' + node.id, node.text, true); }
        };

        function customerAddTab(mytab, myid, myurl, mytitle, myclose) {
            try {

                var tabId = mytab.omTabs('getAlter', 'tab_' + myid);
                if (tabId) {
                    mytab.omTabs('activate', tabId);
                }
                else {
                    if (CreateTabIDs.indexOf('tab_' + myid + ",") < 0) {
                        CreateTabIDs += 'tab_' + myid + ",";
                    }
                    mytab.omTabs("add", {
                        tabId: 'tab_' + myid,
                        title: mytitle,
                        content: "<iframe id='" + myid + "' border=0 frameBorder='no' name='inner-frame' src='" + myurl + "' height='" + ifh + "' width='100%'></iframe>",
                        closable: myclose
                    });
                }
            }
            catch (e) { }
        };

        loadMenu = function () {
            $.ajax({
                type: "GET",
                async: false,
                cache: false,
                url: "Handler/menuTree.ashx",
                dataType: "json",
                beforeSend: function (XMLHttpRequest) {
                    $("#west-panel").html("")
                    $.omMessageBox.waiting({
                        title: '请等待',
                        content: '服务器正在处理请求,请稍后...'
                    });
                },
                success: function (data) {
                    var info = JSON.stringify(data);
                    if (info.indexOf("$ERROR$") > -1) {
                        $.omMessageBox.alert({
                            type: 'error',
                            title: '失败',
                            content: info
                        });
                    }
                    else {
                        $(data).each(function (index, panel) {
                            var temp = "<div id='" + panel.id + "' class='" + panel.mClass + "'>";
                            $(panel.content).each(function (index, mx) {

                                temp += "<div id='" + mx.id + "' class='" + mx.mClass + "' dataurl='" + mx.url + "?menuid=" + mx.menuid + "'>" + mx.title + "</div>"

                            })
                            if (panel.treeId.length > 0) {
                                temp += "<ul class='nav-ul' id='" + panel.treeId + "' dataurl='" + panel.url + "' ></ul>"
                            }
                            $(temp + "</div>").appendTo($("#west-panel"))

                            $("#" + panel.id).omPanel({
                                title: panel.title,
                                collapsed: (panel.id != 'nav-panel-1'),
                                collapsible: true,
                                onCollapse: function () {
                                    $("#west-panel").omScrollbar("refresh");
                                },
                                onExpand: function () {
                                    $("#west-panel").omScrollbar("refresh");
                                }
                            });
                            if ($("#" + panel.treeId)) {
                                $("#" + panel.treeId).omTree({
                                    dataSource: panel.treeContent,
                                    simpleDataModel: true,
                                    onClick: TreeNodeClick
                                });
                            }
                        });
                        $("div[class='nav-item']").bind("click", function (e) {

                            customerAddTab(centerTab, $(this).prop("id"), $(this).attr("dataurl"), $(this).prop("innerText"), true);
                        });
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.omMessageBox.alert({
                        type: 'error',
                        title: '失败',
                        content: XMLHttpRequest.status
                    });
                },
                complete: function (XMLHttpRequest, textStatus) {
                    $.omMessageBox.waiting('close');
                }
            })
        }

        function f_loginout() {
            $.ajax({
                cache: false, async: false,
                url: 'handler/ajax.ashx?type=AjaxSystem&method=loginOut',
                dataType: 'json', type: 'post',
                beforeSend: function () {
                    $.omMessageBox.waiting({
                        title: '请等待',
                        content: '服务器正在处理请求退出,请稍后...'
                    });
                },
                complete: function () {
                    $.omMessageBox.waiting("close");
                    window.top.location.href = decodeURIComponent("Index.aspx");
                },
                success: function (result) {
                },
                error: function (result, b) {
                }
            });
        }

        function f_changepwd() {
            art.dialog.data('currentUID', currentUID);
            art.dialog.open('ChangePWD.aspx', {
                id: 'ChangePWD', width: 500, height: 250, title: '密码修改', lock: true,
                close: function () {
                }
            }, true);
        }
    </script>
</head>
<body>
    <div id="center-panel">
        <div id="center-tab">
            <ul>
                <li><a href="#tab_mydesk">我的桌面</a></li>
            </ul>
            <div id="tab_mydesk">
                <iframe id='mydesk' border="0" frameborder='no' src='' width='100%'></iframe>
            </div>
        </div>
    </div>
    <div id="west-panel" class="om-accordion" style="position: relative;">
    </div>
    <div id="south-panel">
    </div>
</body>
</html>
